Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nearley

Package Overview
Dependencies
Maintainers
2
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nearley

Simple, fast, powerful parser toolkit for JavaScript.

  • 2.20.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.1M
increased by0.68%
Maintainers
2
Weekly downloads
 
Created

What is nearley?

The nearley npm package is a fast, feature-rich, and modern parser toolkit for JavaScript. It is based on Earley's algorithm and can be used to create parsers for complex, context-free grammars. nearley is designed to be simple to use and extend, making it a good choice for building compilers, interpreters, and other language-related tools.

What are nearley's main functionalities?

Grammar Definition

This feature allows you to define a grammar for your language. The grammar is written in a simple, JSON-like format and compiled into a parser.

{"module.exports = grammar({main: $ => ['hello', $.world],world: $ => 'world'});"}

Parsing Input

Once you have defined a grammar, you can create a parser and feed it input to parse. The parser will output a parse tree or a list of possible parse trees if the input is ambiguous.

{"const nearley = require('nearley');\nconst grammar = require('./your-grammar.js');\nconst parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));\nparser.feed('hello world');\nconst results = parser.results;\nconsole.log(results);"}

Error Reporting

nearley provides error reporting features that help you understand where and why a parse failed, which is useful for debugging grammars and providing feedback to users.

{"const nearley = require('nearley');\nconst grammar = require('./your-grammar.js');\nconst parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));\ntry {\n  parser.feed('hello wor');\n} catch (error) {\n  console.error(error.message);\n}"}

Other packages similar to nearley

Keywords

FAQs

Package last updated on 06 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc